"""
这个是运行http测试用例的方法，需要传入http测试用例的excel文件路径和测试执行完以后的路径
Powered By cc
2020/04/06
"""
from common.Excel import ExcelReader, ExcelWriter
from common.tools import getfunc
from interkeywords.interkeyword import HTTPKeyWord


def runHttp(tecasePath,resultTestcasePath):
    """
    使用excel编写的http测试用例的执行
    :param tecasePath:测试用例的excel文件
    :param resultTestcasePath: 测试结果的excel文件
    """
    read = ExcelReader()
    read.open_excel(testcaPath)
    write = ExcelWriter()
    write.openCopyExcel(resultTestcasePath,tecasePath)
    http = HTTPKeyWord(write)
    for sheetIndex in range(read.sheetNum):
        #切换shett页
        read.switchSheetByIndex(sheetIndex)
        write.switchSheetByIndex(sheetIndex)
        #切换该sheet页的行
        for row in range(1,read.rows):
            #读取该行的内容返回的是一个列表
            http.setLine(row)
            line = read.readLine(row)
            if len(line[0])>0 or len(line[1])>0:
                print('这不是用例行')
            else:

                func = getfunc(http,line[3])
                if func is None:
                    print('该关键字%s不存在'%line[3])
                else:
                    if func[1] == 1:
                        func[0](line[4])
                    elif func[1] == 2:
                        func[0](line[4],line[5])
                    else:
                        print('暂不支持超过两个参数')
                if len(line[7])>0:
                    func1 = getfunc(http,line[7])
                    if func1 is None:
                        pass
                    else:
                        func1[0](line[8],line[9])

    write.saveClose()




if __name__=='__main__':
    testcaPath = '../lib/testcases/HTTPLogin.xlsx'
    resultTestcasepath = '../lib/result/resultHTTPLogin.xlsx'
    runHttp(testcaPath,resultTestcasepath)
